#include "IndexBuffer.h"
#include "Utility/Utility.h"

CIndexBuffer::CIndexBuffer(UINT32 dwID, ResourceHandle hHandle, EResourceType eResType, UINT32 dwIndexCount)
	: CHardwareResource(dwID, hHandle, eResType)
	, m_dwIndexCount(dwIndexCount)
{

}

CIndexBuffer::~CIndexBuffer()
{
	
}

void CIndexBuffer::Release()
{
	ID3D10Buffer* pD3DBuf  = (ID3D10Buffer*)m_hRealHandle;
	SAFE_RELEASE(pD3DBuf);
	CHardwareResource::Release();
}

ID3D10Buffer* CIndexBuffer::GetHandle()
{
	return static_cast<ID3D10Buffer*>(m_hRealHandle);
}

void* CIndexBuffer::Lock()
{
	void* pData = NULL;
	ID3D10Buffer* pD3DBuf  = (ID3D10Buffer*)m_hRealHandle;

	HR(pD3DBuf->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&pData));

	return pData;
}

void CIndexBuffer::UnLock()
{
	ID3D10Buffer* pD3DBuf  = (ID3D10Buffer*)m_hRealHandle;
	pD3DBuf->Unmap();
}

